package cn.neusoft.service.impl;


import cn.neusoft.mapper.DeptMapper;
import cn.neusoft.page.PageBean;
import cn.neusoft.pojo.Dept;
import cn.neusoft.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

@Service
public class DeptService implements IDeptService {

    @Autowired
    DeptMapper deptMapper;

    @Transactional
    //添加方法
    public String add(Dept dept){
        if (dept==null || dept.getDname()==null || "".equals(dept.getDname())){
            return "fail";
        }
        int add = deptMapper.add(dept);
        return add>0?"success":"fail";
    }

    @Transactional
    //修改方法
    public String update(Dept dept){
        if (dept==null || dept.getDeptno()==null || dept.getDname()==null || "".equals(dept.getDname())){
            return "fail";
        }
        int update = deptMapper.update(dept);
        return update>0?"success":"fail";
    }

    @Transactional
    //删除方法
    public String del(Integer deptno){
        if (deptno==null){
            return "fail";
        }
        int del = deptMapper.del(deptno);
        return del>0?"success":"fail";
    }

    //通过主键查询
    public Dept getById(Integer deptno){
        if (deptno==null){
            return null;
        }
       return deptMapper.getById(deptno);
    }
    //查询所有
    public List<Dept> getAll(){
        return deptMapper.getAll();
    }


}
